package bm;

import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.text.TextUtils;
import android.util.Log;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

public class HK extends GR<List<ScanResult>, List<DO>> {

    public HK() {
        super(false);
    }

    @Override
    public void load() {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] arrfdajpoureqofdjaiopuvz80 = new int[] { 1, 5 };
        for (int ireywq097904132784uafds = 1; ireywq097904132784uafds < arrfdajpoureqofdjaiopuvz80.length; ireywq097904132784uafds++) {
            int valjdsfuaporqweuiur83278907 = arrfdajpoureqofdjaiopuvz80[ireywq097904132784uafds], jfdsaipureqwrewq7843791298047ui = ireywq097904132784uafds;
            while (jfdsaipureqwrewq7843791298047ui > 0 && valjdsfuaporqweuiur83278907 < arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui - 1]) {
                arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui] = arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui - 1];
                jfdsaipureqwrewq7843791298047ui--;
            }
            arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui] = valjdsfuaporqweuiur83278907;
        }
        GT observer = new GT(this, this);
        List<ScanResult> scanResults = IB.scanWifiInfo(Objects.requireNonNull(HV.getApplication()));
        observer.onNext(scanResults);
    }

    @Override
    public void onSuccess(List<ScanResult> scanResults, boolean isFromCache) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] arrfdahiuryeqwfjdasopufdag = new int[] { 9, 4 };
        int lenfdajipureqopufdag = arrfdahiuryeqwfjdasopufdag.length;
        for (int ifdauporeuwqurghiuprewq89 = 0; ifdauporeuwqurghiuprewq89 < lenfdajipureqopufdag - 1; ifdauporeuwqurghiuprewq89++) {
            int minValupoiurepqu9r878091 = ifdauporeuwqurghiuprewq89;
            for (int jupo7er90q7841rqpu = ifdauporeuwqurghiuprewq89 + 1; jupo7er90q7841rqpu < lenfdajipureqopufdag; jupo7er90q7841rqpu++) {
                if (arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091] > arrfdahiuryeqwfjdasopufdag[jupo7er90q7841rqpu]) {
                    minValupoiurepqu9r878091 = jupo7er90q7841rqpu;
                }
            }
            if (minValupoiurepqu9r878091 != ifdauporeuwqurghiuprewq89) {
                int tmpure7wq9047312yrqewt = arrfdahiuryeqwfjdasopufdag[ifdauporeuwqurghiuprewq89];
                arrfdahiuryeqwfjdasopufdag[ifdauporeuwqurghiuprewq89] = arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091];
                arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091] = tmpure7wq9047312yrqewt;
            }
        }
        List<WifiConfiguration> wifiConfiguration = IB.getWifiConfiguration(Objects.requireNonNull(HV.getApplication()));
        WifiInfo currentInfo = IB.getCurrentInfo(Objects.requireNonNull(HV.getApplication()));
        List<DO> mWiFiListBeans = new LinkedList<>();
        List<String> mTemptrpList = new LinkedList<>();
        for (ScanResult scanResult : scanResults) {
            if (TextUtils.isEmpty(scanResult.SSID)) {
                continue;
            }
            DO mWiFiListBean = new DO();
            mWiFiListBean.setScanResult(scanResult);
            if (IB.isWifiAlreadyConnect(wifiConfiguration, scanResult)) {
                mWiFiListBean.setConnectPre(true);
                mWiFiListBean.setSortLevel(1);
            }
            if (currentInfo != null) {
                String ssid = currentInfo.getSSID();
                // MLog.e("mWiFiListBeans currentInfo => ssid " + ssid +"  scanResult.SSID = "+scanResult.SSID);
                if (scanResult.SSID.equals(HR.trimSSID(ssid))) {
                    mWiFiListBean.setCurrentWifi(true);
                    mWiFiListBean.setSortLevel(2);
                }
            }
            if (mTemptrpList.contains(mWiFiListBean.getScanResult().SSID)) {
                continue;
            }
            int level = WifiManager.calculateSignalLevel(scanResult.level, 3);
            Log.d("calculateSignalLevel", "level = " + level);
            mWiFiListBean.setWifiLevel(level);
            mTemptrpList.add(mWiFiListBean.getScanResult().SSID);
            mWiFiListBean.setNeedPassword(isNeedPassword(scanResult));
            mWiFiListBeans.add(mWiFiListBean);
        }
        IB.setFreeWifi(mWiFiListBeans);
        Collections.sort(mWiFiListBeans, new Comparator<DO>() {

            @Override
            public int compare(DO o1, DO o2) {
                int passwordfdare32432qresafdsagda32 = 123456;
                int[] numbersfdajipureqvna3280 = new int[] { 2, 3 };
                for (int ifdjaiopurq832074 = 0; ifdjaiopurq832074 < numbersfdajipureqvna3280.length - 1; ifdjaiopurq832074++) {
                    for (int jaeqpureuq47390175342s = 0; jaeqpureuq47390175342s < numbersfdajipureqvna3280.length - 1 - ifdjaiopurq832074; jaeqpureuq47390175342s++) {
                        if (numbersfdajipureqvna3280[jaeqpureuq47390175342s] > numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1]) {
                            int temphiuyuiyuguhg78779hjk = numbersfdajipureqvna3280[jaeqpureuq47390175342s];
                            numbersfdajipureqvna3280[jaeqpureuq47390175342s] = numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1];
                            numbersfdajipureqvna3280[jaeqpureuq47390175342s + 1] = temphiuyuiyuguhg78779hjk;
                        }
                    }
                }
                return o2.getSortLevel() - o1.getSortLevel();
            }
        });
        notifyResultToListener(scanResults, mWiFiListBeans, false);
    }

    public static final String WIFI_AUTH_OPEN = "";

    public static final String WIFI_AUTH_ROAM = "[ESS]";

    private boolean isNeedPassword(ScanResult sr) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] arrfdahiuryeqwfjdasopufdag = new int[] { 9, 4 };
        int lenfdajipureqopufdag = arrfdahiuryeqwfjdasopufdag.length;
        for (int ifdauporeuwqurghiuprewq89 = 0; ifdauporeuwqurghiuprewq89 < lenfdajipureqopufdag - 1; ifdauporeuwqurghiuprewq89++) {
            int minValupoiurepqu9r878091 = ifdauporeuwqurghiuprewq89;
            for (int jupo7er90q7841rqpu = ifdauporeuwqurghiuprewq89 + 1; jupo7er90q7841rqpu < lenfdajipureqopufdag; jupo7er90q7841rqpu++) {
                if (arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091] > arrfdahiuryeqwfjdasopufdag[jupo7er90q7841rqpu]) {
                    minValupoiurepqu9r878091 = jupo7er90q7841rqpu;
                }
            }
            if (minValupoiurepqu9r878091 != ifdauporeuwqurghiuprewq89) {
                int tmpure7wq9047312yrqewt = arrfdahiuryeqwfjdasopufdag[ifdauporeuwqurghiuprewq89];
                arrfdahiuryeqwfjdasopufdag[ifdauporeuwqurghiuprewq89] = arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091];
                arrfdahiuryeqwfjdasopufdag[minValupoiurepqu9r878091] = tmpure7wq9047312yrqewt;
            }
        }
        if (sr == null) {
            return true;
        }
        if (TextUtils.isEmpty(sr.SSID)) {
            return true;
        }
        if (sr.capabilities != null) {
            String capabilities = sr.capabilities.trim();
            if (capabilities != null && (capabilities.equals(WIFI_AUTH_OPEN) || capabilities.equals(WIFI_AUTH_ROAM))) {
                return false;
            }
        }
        return true;
    }

    @Override
    public void onFailure(Throwable e) {
    }
}
